<script setup>
import { computed } from 'vue'
import dayjs from 'dayjs'

const props = defineProps({
	showType: {
		type: String,
		default: 'classify'
	},
	item: {
		type: Object,
		default: () => {
			return {
				name: '默认名称',
				picurl: 'https://mp-0cb878b7-99ec-44ea-8246-12b123304b05.cdn.bspapp.com/xxmBizhi/20231010/1696900747351_2102.jpg',
				updateTime: new Date()
			}
		}
	}
})

const DAY = 86400 * 1000
const MONTH = DAY * 30

const updateDate = computed(() => {
	const diffDay = Math.floor((Date.now() - props.item.updateTime) / DAY)
	
	if (diffDay < 30) {
		return diffDay + '天前更新'
	} else if (diffDay > 90) {
		return 0
	} else {
		return Math.floor(diffDay / 30) + '个月前更新'
	}
})

// 跳转至该分类的壁纸列表
const goToWallpaperList = () => {
	uni.navigateTo({
		url: `/pages/wallpaper-list/wallpaper-list?id=${props.item._id}&name=${props.item.name}&type=classify`
	})
}
</script>

<template>
	<view v-if="showType === 'classify'" class="theme-item">
		<view class="img-box" @click="goToWallpaperList">
			<image :src="item.picurl" mode="aspectFill"></image>
			<view class="superscript" v-show="updateDate">
				<text class="updateDate">{{ updateDate }}</text>
			</view>
			<view class="mask">
				{{ item.name }}
			</view>
		</view >
	</view>
	
	<view v-if="showType === 'more'" class="theme-item">
		<navigator class="img-box more-box" url="/pages/classify/classify" open-type="reLaunch">
			<image src="/static/more.jpg" mode="aspectFill"></image>
			<view class="mask">
				<uni-icons type="more-filled" size="32" color="#f9f8f5"></uni-icons>
				<view class="text">
					更多
				</view>
			</view>
		</navigator>
	</view>
</template>

<style scoped lang="scss">
.theme-item {
	.img-box {
		position: relative;
		width: 220rpx;
		height: 345rpx;
		border-radius: 10rpx;
		
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
		
		.superscript {
			position: absolute;
			top: 0;
			left: 0;
			border-top-left-radius: 10rpx;
			border-bottom-right-radius: 10rpx;
			background-color: #928fff;
			color: $uni-text-color-inverse;
			font-size: 20rpx;
			padding: 2rpx 8rpx;
			
			.updateDate {
				&::before {
					content: '';
					display: inline-block;
					width: 6rpx;
					height: 6rpx;
					background-color: currentColor; /* 与文字同色 */
					border-radius: 50%; /* 圆形 */
					margin-right: 8rpx;
					margin-bottom: 5rpx;
					margin-left: 3rpx;
				}
			}
		}
		
		.mask {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 70rpx;
			line-height: 70rpx;
			background-color: rgba(0, 0, 0, 0.2);
			color: $uni-text-color-1;
			border-bottom-left-radius: 10rpx;
			border-bottom-right-radius: 10rpx;
			
			display: flex;
			justify-content: center;
			backdrop-filter: blur(10rpx);
		}
	}
	
	.more-box {
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
		
		.mask {
			width: 100%;
			height: 345rpx;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			border-radius: 10rpx;
		}
		
		.text {
			font-size: 30rpx;
		}
	}
}
</style>